﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Views/Shared/Base.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    CheckDetail
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% 
        Dim cps As Integer = DailyReport.DailyReportCommon.CurrentUserPermissions
        
        If Not (DailyReport.DailyReportCommon.MatchingPermission(cps, DailyReport.DailyReportCommon.PermissionList.一审)) Then
            txtLevel1.Disabled = True
        Else
            txtLevel1.Disabled = False
        End If
        If Not (DailyReport.DailyReportCommon.MatchingPermission(cps, DailyReport.DailyReportCommon.PermissionList.二审)) Then
            txtLevel2.Disabled = True
        Else
            txtLevel2.Disabled = False
        End If
        If Not (DailyReport.DailyReportCommon.MatchingPermission(cps, DailyReport.DailyReportCommon.PermissionList.三审)) Then
            txtLevel3.Disabled = True
        Else
            txtLevel3.Disabled = False
        End If
        If Not (DailyReport.DailyReportCommon.MatchingPermission(cps, DailyReport.DailyReportCommon.PermissionList.审核会签)) Then
            txtLevel4.Disabled = True
        Else
            txtLevel4.Disabled = False
        End If
        If Not (DailyReport.DailyReportCommon.MatchingPermission(cps, DailyReport.DailyReportCommon.PermissionList.地价会签)) Then
            txtLevel5.Disabled = True
        Else
            txtLevel5.Disabled = False
        End If
    %>
    <ext:Viewport ID="ViewPort1" runat="server" Layout="fit">
        <Items>
            <ext:GridPanel ID="GridPanel1" runat="server" Header="false" Border="false" TrackMouseOver="true"
                AutoExpandColumn="Business" SkipIdForNewRecords="true">
                <Store>
                    <ext:Store ID="dcDayCheck" runat="server" AutoSave="false">
                        <Proxy>
                            <ext:HttpProxy Url="/Day/GetCheckDetailStore/" />
                        </Proxy>
                        <UpdateProxy>
                            <ext:HttpWriteProxy Url="/Day/SaveDayCheckWithConfirmation/" />
                        </UpdateProxy>
                        <BaseParams>
                            <ext:Parameter Name="userid" Value="_userid" Mode="Raw" />
                            <ext:Parameter Name="checkdate" Value="_checkdate" Mode="Raw" />
                        </BaseParams>
                        <Reader>
                            <ext:JsonReader IDProperty="id" Root="data" TotalProperty="total" MessageProperty="message">
                                <Fields>
                                    <ext:RecordField Name="ID" />
                                    <ext:RecordField Name="Level1" />
                                    <ext:RecordField Name="Level2" />
                                    <ext:RecordField Name="Level3" />
                                    <ext:RecordField Name="Level4" />
                                    <ext:RecordField Name="Level5" />
                                    <ext:RecordField Name="Urgent" />
                                    <ext:RecordField Name="Crossregion" />
                                    <ext:RecordField Name="CheckDate" />
                                    <ext:RecordField Name="Total" />
                                    <ext:RecordField Name="Business" />
                                    <ext:RecordField Name="UserID" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <SortInfo Field="Business" Direction="ASC" />
                        <Listeners>
                            <Exception Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-exclamation', 
                                    html      : e && e.message ? e.message : response.message || response.statusText, 
                                    title     : '出错啦', 
                                    hideDelay : 5000
                                });" />
                            <Save Handler="
                                Ext.net.Notification.show({
                                    iconCls   : 'icon-information', 
                                    html      : '保存记录成功', 
                                    title     : '保存成功', 
                                    hideDelay : 5000
                                });
                                parent.Store1.reload();" />
                            <Load Handler="updateTotal(#{GridPanel1});" />
                        </Listeners>
                    </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn Width="25" Resizable="false" />
                        <ext:Column ColumnID="ID" DataIndex="ID" Header="ID" Hidden="true">
                            <Editor>
                                <ext:DisplayField ID="DisplayField1" runat="server" StyleSpec="padding-left:5px;font:12px arial, tahoma, helvetica, sans-serif;" />
                            </Editor>
                        </ext:Column>
                        <ext:GroupingSummaryColumn ColumnID="Business" DataIndex="Business" Header="业务" SummaryType="Count">
                            <Editor>
                                <ext:SelectBox ID="sltBusiness" runat="server" AllowBlank="false" DisplayField="text"
                                    ValueField="text" EmptyText="请选择一个业务">
                                    <Store>
                                        <ext:Store runat="server" ID="StoreBusiness">
                                            <Proxy>
                                                <ext:HttpProxy runat="server" Url="/Setting/Business.xml" />
                                            </Proxy>
                                            <Reader>
                                                <ext:XmlReader Record="item">
                                                    <Fields>
                                                        <ext:RecordField Name="value" Mapping="@value" />
                                                        <ext:RecordField Name="text" Mapping="@text" />
                                                    </Fields>
                                                </ext:XmlReader>
                                            </Reader>
                                        </ext:Store>
                                    </Store>
                                    <Listeners>
                                        <Select Fn="afterBusinessSelect" />
                                    </Listeners>
                                </ext:SelectBox>
                                <%--<ext:DisplayField ID="dpBusiness" runat="server" DataIndex="Business"></ext:DisplayField>--%>
                            </Editor>
                            <SummaryRenderer Handler="return ((value === 0 || value > 1) ? value +' 项' : '1 项');" />
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="一审" DataIndex="Level1" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtLevel1" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="二审" DataIndex="Level2" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtLevel2" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="三审" DataIndex="Level3" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtLevel3" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="审核会签" DataIndex="Level4" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtLevel4" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="地价会签" DataIndex="Level5" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtLevel5" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="特殊案" DataIndex="Urgent" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtUrgent" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                        <ext:GroupingSummaryColumn Header="跨区案" DataIndex="Crossregion" Width="100" SummaryType="Sum">
                            <Editor>
                                <ext:NumberField ID="txtCrossregion" runat="server" SelectOnFocus="true">
                                </ext:NumberField>
                            </Editor>
                        </ext:GroupingSummaryColumn>
                    </Columns>
                    <Listeners>
                        <WidthChange Handler="updateTotal(#{GridPanel1});" />
                    </Listeners>
                </ColumnModel>
                <TopBar>
                    <ext:Toolbar ID="Toolbar1" runat="server">
                        <Items>
                            <ext:Button ID="btnSave" runat="server" Text="保存" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{dcDayCheck}.save();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="btnAdd" runat="server" Text="添加" Icon="Add">
                                <Listeners>
                                    <Click Handler="btnSave.disabled = true;btnAdd.disabled = true;#{GridPanel1}.insertRecord(0, { CheckDate: (new Date()).format('Y-m-d'),Level1:0,Level2:0,Level3:0,Level4:0,Level5:0,Urgent:0,Crossregion:0,UserID:-1,Total:0,ID:-1});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.getRowEditor().startEditing(0);" />
                                </Listeners>
                            </ext:Button>
                            <%--<ext:Button ID="Button2" runat="server" Text="Reject Changes" Icon="ArrowUndo">
                                <Listeners>
                                    <Click Handler="#{dcDayCheck}.rejectChanges();" />
                                </Listeners>
                            </ext:Button>--%>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <BottomBar>
                    <ext:Toolbar ID="Toolbar2" runat="server">
                        <Items>
                            <ext:DisplayField ID="DisplayField7" runat="server" Width="25" />
                            <ext:DisplayField ID="ColumnField1" runat="server" DataIndex="Business" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField2" runat="server" DataIndex="Level1" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField3" runat="server" DataIndex="Level2" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField4" runat="server" DataIndex="Level3" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField5" runat="server" DataIndex="Level4" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField6" runat="server" DataIndex="Level5" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField8" runat="server" DataIndex="Urgent" Cls="total-field"
                                Text="-" />
                            <ext:DisplayField ID="DisplayField9" runat="server" DataIndex="Crossregion" Cls="total-field"
                                Text="-" />
                        </Items>
                    </ext:Toolbar>
                </BottomBar>
                <Listeners>
                    <ColumnResize Handler="updateTotal(this);" />
                    <%--<AfterRender Handler="updateTotal(this);" Delay="100" />--%>
                </Listeners>
                <Plugins>
                    <ext:RowEditor ID="RowEditor" runat="server" ErrorSummary="false" ClicksToEdit="1"
                        CancelText="取消" SaveText="确认">
                        <Listeners>
                            <BeforeEdit Fn="setRowEditorState" />
                            <CancelEdit Fn="rowCancelEdit" />
                            <AfterEdit Fn="AfterRowEdit" />
                        </Listeners>
                    </ext:RowEditor>
                    <ext:GroupingSummary ID="GroupingSummary1" runat="server" />
                </Plugins>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderArea" runat="server">
    <style type="text/css">
        .x-grid3-cell-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        
        .x-grid-group-hd div
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
        }
        
        .x-grid3-hd-inner
        {
            font-family: "segoe ui" ,tahoma, arial, sans-serif;
            font-size: 12px;
        }
        
        .x-grid3-body .x-grid3-td-Cost
        {
            background-color: #f1f2f4;
        }
        
        .x-grid3-summary-row .x-grid3-td-Cost
        {
            background-color: #e1e2e4;
        }
        
        .total-field
        {
            background-color: #fff;
            font-weight: bold !important;
            color: #000;
            border: solid 1px silver;
            padding: 2px;
            margin-right: 5px;
        }
    </style>
    <script type="text/javascript">
        var updateTotal = function (grid) {
            var fbar = grid.getBottomToolbar(),
                column,
                field,
                width,
                data = {},
                c,
                cs = grid.view.getColumnData();

            for (var j = 0, jlen = grid.store.getCount(); j < jlen; j++) {
                var r = grid.store.getAt(j);

                for (var i = 0, len = cs.length; i < len; i++) {
                    c = cs[i];
                    column = grid.getColumnModel().columns[i];

                    if (column.summaryType) {
                        data[c.name] = Ext.grid.GroupSummary.Calculations[column.summaryType](data[c.name] || 0, r, c.name, data);
                    }
                }
            }

            for (var i = 0; i < grid.getColumnModel().columns.length; i++) {
                column = grid.getColumnModel().columns[i];

                if (column.dataIndex != grid.store.groupField) {
                    field = fbar.findBy(function (item) {
                        return item.dataIndex === column.dataIndex;
                    })[0];

                    if (typeof (field) != 'undefined') {
                        c = cs[i];
                        fbar.remove(field, false);
                        fbar.insert(i, field);
                        width = grid.getColumnModel().getColumnWidth(i);
                        field.setWidth(width - 5);
                        field.setValue((column.summaryRenderer || c.renderer)(data[c.name], {}, {}, 0, i, grid.store));
                    }
                }
            }

            fbar.doLayout();
        }
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="StartupArea" runat="server">
    <script type="text/javascript">
        var _userid = '<%=ViewData("UserID") %>';
        var _checkdate = '<%=ViewData("CheckDate") %>';

        var setRowEditorState = function (el, rowIndex) {
            var cd = new Date(_checkdate);
            var td = new Date();
            if (cd.format('Y-m-d') != td.format('Y-m-d')) {
                return false;
            } else {
                if (GridPanel1.store.data.items[rowIndex].data['Business'] != "") {
                    sltBusiness.disabled = true;
                } else {
                    sltBusiness.disabled = false;
                }
            }
            btnSave.disabled = true;
            btnAdd.disabled = true;
        }

        var rowCancelEdit = function (el, forced) {
            //debugger;
            //var d = GridPanel1.store.data
            if (GridPanel1.store.data.items[0].data['Business'] == "") {
                GridPanel1.store.remove(GridPanel1.store.data.items[0]);
            }
            btnSave.disabled = false;
            btnAdd.disabled = false;
        }

        var AfterRowEdit = function (el, o, r, rowIndex) {
            btnSave.disabled = false;
            btnAdd.disabled = false;
        }

        var afterBusinessSelect = function (item, record, index) {
            var odata = GridPanel1.store.data;
            for (i = 0; i < GridPanel1.store.data.items.length; i++) {
                if (GridPanel1.store.data.items[i].data['Business'] == record.data.text) {
                    Ext.Msg.show({
                        title: 'DailyReport',
                        buttons: { yes: '确认' },
                        msg: '列表中已包含相同的业务。',
                        fn: function (btn) {
                            item.clear();
                            return false;
                        }
                    });

                }
            }
        }

        Ext.onReady(function () {
            var cd = new Date(_checkdate);
            var td = new Date();

            if (cd.format('Y-m-d') != td.format('Y-m-d')) {
                btnSave.hide();
                btnAdd.hide();
            }
        });
    </script>
</asp:Content>
